package MapApi;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;

public class GetMap2 {
    public static void main(String[] args) {
         /*
    | V   get(Object key)              | 根据键获取值             |
    | -------------------------------- | ------------------------ |
    | Set<K>   keySet()                | 获取所有键的集合         |
    | Collection<V>   values()         | 获取所有值的集合         |
    | Set<Map.Entry<K,V>>   entrySet() | 获取所有键值对对象的集合 |
     */

        Map<String,String> map=new HashMap<>();

        map.put("德莉莎","花lin");
        map.put("张无忌","赵敏");
        map.put("郭靖","黄蓉");
        map.put("杨过","小龙女");

        Set<Map.Entry<String, String>> entries = map.entrySet();
        //增强for
        for (Map.Entry<String, String> entry : entries) {
            String key = entry.getKey();
            String value = entry.getValue();

            System.out.println(key+"="+value);
        }
        System.out.println("==================================");
        //lambda表达式foreach
        entries.forEach(stringStringEntry -> {
            String key = stringStringEntry.getKey();
            String value = stringStringEntry.getValue();
            System.out.println(key+"="+value);
        });
        System.out.println("==================================");
        //迭代器
        Iterator<Map.Entry<String, String>> iterator = entries.iterator();
        while (iterator.hasNext()){
            Map.Entry<String, String> m = iterator.next();
            String key = m.getKey();
            String value = m.getValue();
            System.out.println(key+"="+value);
        }
    }
}
